package com.ss.android.article.base.feature.user.social;

import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Message;
import android.support.v4.content.ContextCompat;
import android.text.InputFilter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.bytedance.common.utility.collection.WeakList;
import com.bytedance.common.utility.collection.WeakHandler;
import com.bytedance.common.utility.collection.WeakHandler.Callback;
import com.ss.android.article.base.app.AppData;
import com.ss.android.article.base.feature.app.a.ArticleConstants;
import com.ss.android.article.base.feature.model.Article;
import com.ss.android.article.browser.R;
import com.ss.android.common.util.UrlBuilder;
import com.ss.android.model.AbsArticle;
import com.ss.android.newmedia.BaseAppData;
import com.ss.android.newmedia.a.PopupToast;
import com.ss.android.newmedia.activity.browser.BrowserActivity;
import com.ss.android.newmedia.activity.FragmentActivity;

import org.json.JSONException;
import org.json.JSONObject;

import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class ReportActivity extends FragmentActivity implements Callback {
    int a;
    EditText b;
    WeakList<View> c;
    long d;
    long e;
    int f;
    String g;
    int h;
    long i;
    long j;
    String k;
    boolean l;
    WeakHandler m;
    WeakReference n;
    InputMethodManager o;
    ScrollView p;
    boolean q;
    long r;
    long s;
    long t;
    private AppData u;
    private PopupToast v;
    private View w;
    private boolean x;
    private final View.OnClickListener y;
    private final View.OnClickListener z;

    public ReportActivity() {

        this.a = -1;
        this.c = new WeakList();
        this.j = 0;
        this.l = false;
        this.m = new WeakHandler(((Callback) this));
        this.y = new com.ss.android.article.base.feature.user.social.a(this);
        this.z = new com.ss.android.article.base.feature.user.social.b(this);
        new g(this);
    }

    public static void a(Context arg6, AbsArticle arg7, long arg8, int arg10) {
        int v4 = 4;
        if (arg7 != null) {
            int v0 = AppData.getInstance().enableWapReport == 1 ? 1 : 0;
            if (v0 != 0) {
                String v0_1 = arg10 == v4 ? arg6.getString(com.ss.android.article.browser.R.string.a08) : arg6.getString(com.ss.android.article.browser.R.string.a06);
                Intent v2 = new Intent(arg6, BrowserActivity.class);
                v2.putExtra("title", v0_1);
                v2.putExtra("swipe_mode", 2);
                v2.putExtra("hide_more", true);
                v2.putExtra("screen_name", "report");
                JSONObject v1 = new JSONObject();
                try {
                    v1.put("group_id", String.valueOf(arg7.groupId));
                    v1.put("item_id", String.valueOf(arg7.itemId));
                } catch (JSONException v0_2) {
                    v0_2.printStackTrace();
                }

                v2.putExtra("screen_context", v1.toString());
                UrlBuilder v0_3 = new UrlBuilder(ArticleConstants.feedbackWapListFeedbackUrl);
                v0_3.addParam("groupid", arg7.groupId);
                v0_3.addParam("adid", arg8);
                v0_1 = v0_3.build();
                AppData.getInstance();
                v2.setData(Uri.parse(android.support.design.a.a(v0_1, AppData.isNightMode())));
                arg6.startActivity(v2);
                return;
            }

            Intent v0_4 = new Intent(arg6, ReportActivity.class);
            v0_4.putExtra("group_id", arg7.groupId);
            v0_4.putExtra("item_id", arg7.itemId);
            v0_4.putExtra("aggr_type", arg7.aggrType);
            v0_4.putExtra("ad_id", arg8);
            if (arg10 == v4 && ((arg7 instanceof Article))) {
                v0_4.putExtra("report_video_id", ((Article) arg7).videoId);
            }

            v0_4.putExtra("report_type", arg10);
            arg6.startActivity(v0_4);
        }
    }

    public static void a(Context arg3, String arg4) {
        String v0 = arg3.getString(com.ss.android.article.browser.R.string.a07);
        Intent v1 = new Intent(arg3, BrowserActivity.class);
        v1.putExtra("title", v0);
        v1.putExtra("swipe_mode", 2);
        v1.putExtra("hide_more", true);
        v1.putExtra("screen_name", "report");
        AppData.getInstance();
        v1.setData(Uri.parse(android.support.design.a.a(arg4, AppData.isNightMode())));
        arg3.startActivity(v1);
    }

    static TextView a(ReportActivity arg1) {
        return arg1.mRightBtn;
    }

    final void a() {
        this.p.postDelayed(new c(this), 100);
    }

    final void a(int arg2, int arg3) {
        if (this.v == null) {
            this.v = new PopupToast(((Context) this));
        }

        this.v.showToast(arg2, arg3);
    }

    final void a(boolean arg6) {
        int v1;
        int v0 = R.string.delete_success;
        int v4 = 3;
        if (this.isViewValid()) {
            this.l = false;
            this.q = true;
            AppData.isNightMode();
            if (arg6) {
                v1 = R.drawable.g7;
                if (this.h != v4) {
                    v0 = R.string.toast_report_ok;
                }

                this.a(v1, v0);
                this.setResult(-1);
            } else {
                v1 = R.drawable.g6;
                if (this.h != v4) {
                    v0 = R.string.toast_report_fail;
                }

                this.a(v1, v0);
                this.setResult(0);
            }

            if (this.n != null) {
                Object v0_1 = this.n.get();
                if (v0_1 != null && (((ProgressDialog) v0_1).isShowing())) {
                    ((ProgressDialog) v0_1).dismiss();
                }
            }

            this.m.postDelayed(new com.ss.android.article.base.feature.user.social.h(this), 1500);
        }
    }

    static TextView b(ReportActivity arg1) {
        return arg1.mRightBtn;
    }

    static TextView c(ReportActivity arg1) {
        return arg1.mRightBtn;
    }

    static TextView d(ReportActivity arg1) {
        return arg1.mRightBtn;
    }

    static TextView e(ReportActivity arg1) {
        return arg1.mRightBtn;
    }

    public int getDayBackgroundRes() {
        return R.color.ssxinmian4;
    }

    public int getLayout() {
        return R.layout.report_activity;
    }

    public int getNightBackgroundRes() {
        return R.color.t0;
    }

    public void handleMsg(Message message) {
        switch (message.what) {
            case 1034: {
                this.a(true);
                break;
            }
            case 1035: {
                this.a(false);
                break;
            }
        }
    }

    public void init() {
        int v2;
        int v4;
        List v1;
        AppData v1_2;
        int v10 = 2;
        String v3 = null;
        long v8 = 0;
        super.init();
        this.u = AppData.getInstance();
        this.o = (InputMethodManager) this.getSystemService(INPUT_METHOD_SERVICE);
        this.b = (EditText) this.findViewById(R.id.content);
        this.p = (ScrollView) this.findViewById(R.id.scroll_view);
        this.w = this.findViewById(com.ss.android.article.browser.R.id.tv_report_contact);
        this.mTitleView.setText(com.ss.android.article.browser.R.string.a06);
        this.mRightBtn.setVisibility(View.VISIBLE);
        this.mRightBtn.setText(com.ss.android.article.browser.R.string.label_commit);
        this.mRightBtn.setOnClickListener(this.z);
        this.mRightBtn.setEnabled(false);
        Intent v0 = this.getIntent();
        if (v0 == null) {
            this.finish();
        } else {
            this.h = v0.getIntExtra("report_type", 0);
            this.i = v0.getLongExtra("user_id", v8);
            this.d = v0.getLongExtra("group_id", v8);
            this.e = v0.getLongExtra("item_id", v8);
            this.f = v0.getIntExtra("aggr_type", 0);
            this.j = v0.getLongExtra("ad_id", v8);
            this.k = v0.getStringExtra("report_video_id");
            this.r = v0.getLongExtra("report_user_group_id", v8);
            this.s = v0.getLongExtra("report_user_comment_id", v8);
            this.t = v0.getLongExtra("report_user_update_id", v8);
            if (this.h == 0) {
                this.g = this.u.W;
            }

            if (this.h == 1) {
                this.mTitleView.setText(com.ss.android.article.browser.R.string.a07);
            } else if (this.h == v10) {
                this.mTitleView.setText(com.ss.android.article.browser.R.string.a06);
            } else if (this.h == 3) {
                this.mTitleView.setText(com.ss.android.article.browser.R.string.delete_reason);
                this.w.setVisibility(View.GONE);
                this.b.setFilters(new InputFilter[]{
                        new com.ss.android.article.base.feature.user.social.d(this)});
                this.b.setHint(com.ss.android.article.browser.R.string.delete_reason_input_hint);
            } else if (this.h == 4) {
                this.mTitleView.setText(com.ss.android.article.browser.R.string.a08);
            }

            this.u.W = v3;
            if (this.h != 0 || this.d > v8) {
                if (this.h == 1 && this.i <= v8) {
                    this.finish();
                    return;
                }

                if (this.h == v10 && this.d <= v8) {
                    this.finish();
                    return;
                }

                if (this.h == 4 && this.d <= v8) {
                    this.finish();
                    return;
                }
            } else {
                this.finish();
                return;
            }

            this.b.addTextChangedListener(new e(this));
            this.b.setOnClickListener(new f(this));
            boolean v0_1 = AppData.isNightMode();
            if (v0_1 != this.x) {
                this.x = v0_1;
                this.b.setBackgroundResource(com.ss.android.article.browser.R.drawable.i6);
                this.b.setTextColor(this.getResources().getColor(com.ss.android.article.browser.R.color.ssxinzi1));
                this.b.setHintTextColor(this.getResources().getColor(com.ss.android.article.browser.R.color.p3));
                ((TextView) this.findViewById(com.ss.android.article.browser.R.id.tv_report_contact)).setTextColor(ContextCompat.getColor(((Context) this), R.color.ssxinzi3));
            }

            View v0_2 = this.findViewById(com.ss.android.article.browser.R.id.report_options);
            AppData.isNightMode();
            switch (this.h) {
                case 0: {
                    v1_2 = this.u;
                    if (v1_2.bY != null) {
                        v1 = v1_2.bY;
                        break;
                    }
                    v1_2.bY = new ArrayList();
                    BaseAppData.a(((BaseAppData) v1_2).ct, v1_2.bY);
                    v1 = v1_2.bY;
                    break;
                }
                case 1: {
                    v1_2 = this.u;
                    if (((BaseAppData) v1_2).bZ != null) {
                        v1 = ((BaseAppData) v1_2).bZ;
                        break;
                    }

                    ((BaseAppData) v1_2).bZ = new ArrayList();
                    BaseAppData.a(((BaseAppData) v1_2).cu, ((BaseAppData) v1_2).bZ);
                    v1 = ((BaseAppData) v1_2).bZ;
                    break;
                }
                case 2: {
                    v1_2 = this.u;
                    if (v1_2.N != null) {
                        v1 = v1_2.N;
                        break;
                    }

                    v1_2.N = new ArrayList();
                    AppData.a(v1_2.essayReportOptions, v1_2.N);
                    v1 = v1_2.N;
                    break;
                }
                case 3: {
                    String v1_1 = this.u.forumSettings;
                    if (android.support.design.a.isTextEmpty(v1_1)) {
                        v1 = ((List) null);
                        break;
                    }

                    v1 = com.ss.android.article.common.b.b.a().a(v1_1);
                    break;
                }
                case 4: {
                    v1_2 = this.u;
                    if (((BaseAppData) v1_2).ca != null) {
                        v1 = ((BaseAppData) v1_2).ca;
                        break;
                    }

                    ((BaseAppData) v1_2).ca = new ArrayList();
                    BaseAppData.a(((BaseAppData) v1_2).cv, ((BaseAppData) v1_2).ca);
                    v1 = ((BaseAppData) v1_2).ca;
                    break;
                }
                default: {
                    v1 = ((List) null);
                    break;
                }
            }

            label_166:
            if (v1 == null) {
                ArrayList v1_3 = new ArrayList();
            }

            if (v1.isEmpty()) {
                switch (this.h) {
                    case 0: {
                        v4 = R.array.x;
                        v2 = R.array.a2;
                        break;
                    }
                    case 1: {
                        v4 = R.array.a0;
                        v2 = R.array.a1;
                        break;
                    }
                    case 2: {
                        v4 = R.array.v;
                        v2 = R.array.w;
                        break;
                    }
                    case 3: {
                        v4 = R.array.y;
                        v2 = R.array.z;
                        break;
                    }
                    case 4: {
                        v4 = R.array.a3;
                        v2 = R.array.a4;
                        break;
                    }
                    default: {
                        v4 = R.array.x;
                        v2 = R.array.a2;
                        break;
                    }
                }

                String[] v4_1 = this.getResources().getStringArray(v4);
                int[] v6 = this.getResources().getIntArray(v2);
                int v7 = v4_1.length;
                for (v2 = 0; v2 < v7; ++v2) {
                    com.ss.android.newmedia.activity.a.a v8_1 = new com.ss.android.newmedia.activity.a.a();
                    v8_1.b = v4_1[v2];
                    v8_1.a = v6[v2];
                    v1.add(v8_1);
                }
            }

            LayoutInflater v4_2 = LayoutInflater.from(((Context) this));
            Iterator v6_1 = v1.iterator();
            while (v6_1.hasNext()) {
                Object v1_4 = v6_1.next();
                View v7_1 = v4_2.inflate(com.ss.android.article.browser.R.layout.hw, ((ViewGroup) null), false);
                View v2_1 = v7_1.findViewById(com.ss.android.article.browser.R.id.a8q);
                ((TextView) v2_1).setTextColor(ContextCompat.getColorStateList(((Context) this), R.color.yg));
                v7_1.findViewById(com.ss.android.article.browser.R.id.a8p).setBackgroundResource(com.ss.android.article.browser.R.drawable.i4);
                this.c.add(v7_1);
                ((TextView) v2_1).setText(((com.ss.android.newmedia.activity.a.a) v1_4).b);
                v7_1.setTag(Integer.valueOf(((com.ss.android.newmedia.activity.a.a) v1_4).a));
                v7_1.setOnClickListener(this.y);
                ((LinearLayout) v0_2).addView(v7_1);
            }
        }
    }

    public void onDestroy() {
        if (this.v != null) {
            this.v.onDestroy();
            this.v = null;
        }

        super.onDestroy();
    }
}

